package com.nl.lib_project.adapter

import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.nl.lib_project.R
import com.nl.lib_project.entity.AlzheimerLookBackAnswersEntity

class AlzheimerLookBackParentAdapter :
    BaseQuickAdapter<AlzheimerLookBackAnswersEntity, BaseViewHolder>(
        R.layout.item_alzheimer_look_back_parent) {
  override fun convert(holder: BaseViewHolder, item: AlzheimerLookBackAnswersEntity) {
    val recyclerView = holder.getView<RecyclerView>(R.id.mRecyclerView)
    val adapter = AlzheimerLookBackChildAdapter()
    adapter.setNewInstance(item.answers)
    // 正确总计
    var total = 0
    item.answers?.forEach {
      if (it.mValue == true) {
        total++
      }
    }
    holder.getView<TextView>(R.id.mTotalTV).text = total.toString()
    holder.getView<TextView>(R.id.mTimeTV).text = item.time
    recyclerView.adapter = adapter
    recyclerView.layoutManager = GridLayoutManager(context, 2)
  }
}
